There are a whole host of easy - to - commit and hard - to - detect programming errors that are entirely eliminated by using immutable objects , such as failure to synchronize access across threads or failing to clone an array or object before storing a reference to it 使用不變對象可以徹底消除許多容易發(fā)生但難以檢測的編程錯誤,如無法在線程間同步訪問或在存儲對數(shù)組或?qū)ο蟮囊们盁o法克隆該數(shù)組或?qū)ο蟆?